var comparePage = avalon.define({
    $id: "comparePage",
    layout: true,
    data: {
        products: [],
        attrs: [],
        datas: []
    }
});

function escape2Html(str) {
    var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' };
    return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function(all, t) { return arrEntities[t]; });
}

avalon.filters.getData = function(attrId, productId) {
    var datas = comparePage.data.datas;
    var key = productId + "_" + attrId;
    if (null == datas[key]) {
        return "--";
    } else {
        return escape2Html(datas[key]);
    }
};


mui.ready(function() {
    var id = $.getParameter("id");
    var mui_productCompare = mui('#productCompare');
    mui.init({
        gestureConfig: {
            tap: true, //默认为true 
            doubletap: true, //默认为false 
            longtap: true
        }
    });

    mui.ajax('/product/compare.json', {
        data: {
            productIds: id
        },
        dataType: 'json',
        success: function(data) {
            if (data.attrs == '') {
                $("#loading").remove();
                var btnArray = ['YES'];
                mui.confirm('Currently there is no relevant comparative data', 'Prompt', btnArray, function(e) {
                    window.history.go(-1);
                })
            } else {
                comparePage.data = data;
                var pp = window.screen.height;
                //				if(true==mui.os.android){
                //					pp=pp-window.screenTop;
                //pp-160
                //				}
                $('#example').mobileFixedColumnsTable({
                    'sScrollY': pp == 812 ? pp - 160 - 24 : pp - 160,
                    'sScrollX': '100%',
                    'bScrollCollapse': true,
                    'oLanguage': {
                        'sInfo': ''
                    }
                });
            }
        }
    });
    mui(".mui-bar-nav").on('tap', '.mui-icon-white', function() {
        sessionStorage.setItem('todo', 1)
    })
});